package com.hsj.goldstore.mvp.model;

import android.util.Log;

import com.hsj.goldstore.base.BaseBean;
import com.hsj.goldstore.base.BaseModel;
import com.hsj.goldstore.base.ResultCallback;
import com.hsj.goldstore.utils.rxjava.ApiCaback;
import com.hsj.goldstore.utils.rxjava.ObserCallback;

import java.util.HashMap;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2018/3/22.
 */

public class LoginModel extends BaseModel implements ILoginModel {
    private static final String TAG = "LoginModel";

    @Override
    public void chekToken(final ResultCallback callback) {
        addSubscribe(apiStore.tokenCheck(), new ObserCallback(new ApiCaback() {
            @Override
            public void onSuccess(Object data) {
                callback.onSuccess(data, 0, "请求成功");
            }

            @Override
            public void onFailure(int code, String msg) {
                callback.onFalure(code, msg);
            }
        }));
    }

    /**
     * @param phone
     * @param pwd
     * @param callback 登录接口
     */
    @Override
    public void login(String phone, String pwd, final ResultCallback callback) {
        HashMap<String, String> map = new HashMap<>();
        map.put("mobile", phone);
        map.put("password", pwd);
        addSubscribe(apiStore.login(map), new ObserCallback(new ApiCaback<BaseBean<LoginModel>>() {
            @Override
            public void onSuccess(BaseBean<LoginModel> data) {
                callback.onSuccess(data, 0, "登录成功");
            }

            @Override
            public void onFailure(int code, String msg) {
                callback.onFalure(code, msg);
            }
        }));
    }
}
